import QtQuick 2.0
import GizmoController 1.0
import QtGraphicalEffects 1.15

Rectangle {
    id: root
    implicitWidth: 200
    implicitHeight: 200
    radius: windowRadius
    signal windowClose()
    property int windowRadius: 12
    property int titleHeight: 28
    property alias title: windowTitle.text
    property bool _needCloseBtn: true
    function show() { mutexCheck() }
    function close() { visible = false; windowClose()}

    layer.enabled: true
    layer.effect: DropShadow {
        color: Theme.window_border_shadow_color
        samples: 37
        radius: 20
    }

    function mutexCheck() {
        for( var i = 0; i < MutexWindowControl.windows.length; i ++ ){
            if( MutexWindowControl.windows[i].visible ){ MutexWindowControl.windows[i].close() }
        }
        visible = true;
    }

    Component.onCompleted: {
        MutexWindowControl.windows.push(this)
    }

    MouseArea {
        anchors.fill: parent
        onWheel: {}
        onPressed: { mouse.accepted = true; focus = true }
    }

    Rectangle {
        id: titleBar
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        implicitHeight: titleHeight
        color: Theme.normal_window_title_color
        radius: parent.radius

        Rectangle {
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            implicitHeight: parent.height / 2
            color: Theme.normal_window_title_color
        }

        CusText {
            id: windowTitle
            color: "white"
            font.pixelSize: Theme.font_size_14
            font.weight: Font.Medium

            anchors.left: parent.left
            anchors.verticalCenter: parent.verticalCenter
            anchors.leftMargin: 10
        }

        CusCloseBtn {
            id: closeBtn
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            implicitHeight: parent.height
            implicitWidth: height
            color: "transparent"
            visible: _needCloseBtn
            radius: windowRadius
            source_image_normal: "qrc:/image/toolbar_close.svg"
            source_image_hovered: "qrc:/image/toolbar_close.svg"
        }
    }

    Rectangle {
        id: contentBg
        anchors.top: titleBar.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        radius: parent.radius

        Rectangle {
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            implicitHeight: parent.height / 2
        }
    }
}


